Re:JavaScript Validation of only "|" (pipe) in the
[quote="rangana":2dw8jcem]A basic example:
[code:2dw8jcem]
<input type="text" value="t|e|s|t" onblur="alert(this.value.indexOf('|')>-1?'Pipe should not exist.':'It\'s a valid input');">
[/code:2dw8jcem][/quote:2dw8jcem]
the above code is working very fine but
My requirement is , when i enter "|" (pipe) it must not show in the text grid . Please see my code and reply me ASAP .
The below code is my text area
[code:2dw8jcem]
<textarea rows="4" cols="40" onKeyDown="textCounter(this.form.UNFCCC_Comments,this.form.remLen, 250)" onKeyUp="textCounter(this.form.UNFCCC_Comments,this.form.remLen, 250)" >
[/code:2dw8jcem]
The below code is JS
[code:2dw8jcem]
function textCounter(field, countfield, maxlimit) {
//var re = /^[a-zA-Z0-9\n\r\f]*$/; // checking for all the special characters.
var re = "t|e|s|t" ;
if (!re.test(field.value))
{
field.value = field.value.replace(('|'),"");
//alert(this.value.indexOf('|')>-1?'Pipe should not exist.':'It\'s a valid input');
}
else if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
else // otherwise, update 'characters left' counter
countfield.value = maxlimit - field.value.length;
}
function trim(str)
{
return str.replace(/^\s*|\s*$/g,"");
}
function startsWith(str1, str2)
{
return (str1.match("^"+str2)==str2);
}
function endsWith(str1, str2)
{
return (str1.match(str2+"$")==str2)
}
[/code:2dw8jcem]